const {findDataByPage} = require('../util/db-util')
const {setStatus, initShareMsg, setOneShare} = require('../model/share/getShare')
let {shareMsg} = require('../model/share/shareMsg')

function compare(property) {
    return function (a, b) {
        let value1 = a[property];
        let value2 = b[property];
        return value1 - value2;
    }
}

async function getPublicShare(page = 1, size = 6) {
    let shareList = await findDataByPage('share', '*', parseInt((page - 1) * size), parseInt(size))
    initShareMsg(shareMsg)
    setStatus(shareMsg, 1)
    for (let item of shareList) {
        shareMsg.shareList.push(await setOneShare(item))
    }
    return shareMsg
}

module.exports = {
    getPublicShare
}